﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using mesoBoard.Common.UrlHelpers;

namespace mesoBoard.Common.HtmlHelpers
{
    public static class AdminHtmlHelpers
    {
        /// <summary>
        /// Creates a link to the admin operation confirmation page.
        /// </summary>
        /// <param name="LinkText">The link text.</param>
        /// <param name="YesRedirectURL">URL to redirect to for YES response.</param>
        /// <param name="NoRedirectUrl">URL to redirect to for NO response.</param>
        /// <returns></returns>
        public static string AdminConfirm(this HtmlHelper html, string LinkText, string YesRedirectUrl, string NoRedirectUrl)
        {
            return html.ActionLink(LinkText, "Confirm", "Admin",
            new
            {
                YesRedirect = YesRedirectUrl,
                NoRedirect = NoRedirectUrl,
                area = "Admin"
            }, null).ToString();
        }

        public static string AdminDeleteImageLink(this HtmlHelper html, string YesRedirectUrl, string NoRedirectUrl, string AltText)
        {
            UrlHelper Url = new UrlHelper(html.ViewContext.RequestContext);

            TagBuilder link = new TagBuilder("a");
            link.MergeAttribute("href", Url.AdminConfirmUrl(YesRedirectUrl, NoRedirectUrl));

            TagBuilder img = new TagBuilder("img");
            img.MergeAttribute("src", Url.Content("~/Areas/Admin/Content/images/delete.png"));
            img.MergeAttribute("alt", AltText);
            img.MergeAttribute("title", AltText);

            link.InnerHtml = img.ToString();

            return link.ToString();
        }
    }
}